package io.github.junxworks.qt.modules.mm.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import io.github.junxworks.ep.core.orm.TBaseMapper;
import io.github.junxworks.qt.modules.mm.dto.MmModelCondition;
import io.github.junxworks.qt.modules.mm.entity.MmModel;
import io.github.junxworks.qt.modules.mm.vo.MmExpressionVo;
import io.github.junxworks.qt.modules.mm.vo.MmModelVo;

@Mapper
public interface MmModelMapper extends TBaseMapper<MmModel> {

	List<MmModelVo> queryList(MmModelCondition condition);

	@Select("select * from mm_model where id=#{id}")
	MmModelVo queryMmModelById(@Param("id") Long id);

	@Select("select * from mm_model where model_name=#{name} and status=0")
	MmModelVo queryMmModelByName(String name);

	@Select("select * from mm_model where model_no=#{no} and status=0")
	MmModelVo queryMmModelByNo(String no);

	@Select("select exp.*,u.name `create_user_name` from mm_model_exp_rela mer,mm_expression exp,ep_s_user u where u.id=exp.create_user and mer.model_id=#{id} and mer.exp_id=exp.id and exp.status=0 order by exp.priority asc,exp.id desc")
	List<MmExpressionVo> queryExpressionsByModelId(Long id);

	@Delete("delete from mm_model_exp_rela where model_id=#{id}")
	int deleteModelExpRelaByModelId(Long dsId);

	List<Long> queryAllExpIds(@Param("modelNos") List<String> modelNos);
}